package com.qjq.glasses_shopping.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qjq.glasses_shopping.mapper.PermissionMapper;
import com.qjq.glasses_shopping.pojo.Permission;
import com.qjq.glasses_shopping.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 权限服务
 */
@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    //新增权限
    @Override
    public void add(Permission permission) {
        permissionMapper.insert(permission);
    }

    //修改权限
    @Override
    public void update(Permission permission) {
        permissionMapper.updateById(permission);
    }

    //删除权限
    @Override
    public void delete(Long id) {
        //删除权限
        permissionMapper.deleteById(id);
        //删除权限对应的角色
        permissionMapper.deletePermissionAllRole(id);
    }

    //根据id查询权限
    @Override
    public Permission findById(Long id) {
        return permissionMapper.selectById(id);
    }

    //分页查询权限
    @Override
    public Page<Permission> search(int page, int size) {
        Page<Permission> permissionPage = permissionMapper.selectPage(new Page<>(page, size), null);
        return permissionPage;
    }

    //查询全部权限
    @Override
    public List<Permission> findAll() {
        return permissionMapper.selectList(null);
    }
}
